//
//  DrawControllerViewController.m
//  IOSApplication
//
//  Created by 麻再挺 on 2019/5/22.
//  Copyright © 2019 麻再挺. All rights reserved.
//

#import "DrawControllerViewController.h"
#import <MMDrawerController/MMDrawerController.h>
#import "MenuViewController.h"
#import "./worm/WormViewController.h"

@interface DrawControllerViewController ()

@end

@implementation DrawControllerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // 设置背景为白色
    [UIApplication sharedApplication].keyWindow.backgroundColor = UIColor.whiteColor;

    // 控制器 数组
    NSArray *controllerArr = @[@"WormViewController", @"UIViewController", @"UIViewController", @"UIViewController"];
    // Tab 显示文字 数组
    NSArray *titleArr = @[@"图虫", @"图虫", @"图虫", @"图虫"];
    // 图片数组
    NSArray *picArr = @[@"message.png", @"knowledge.png", @"book.png", @"me.png"];
    // 已添加的控制器数组
    NSMutableArray *array = [NSMutableArray new];
    // 创建 TabController
    UITabBarController *tb = [UITabBarController new];
    // 遍历数组
    for (int i = 0; i < controllerArr.count; i++) {
        // 根据字符串获取类
        Class cl = NSClassFromString(controllerArr[i]);
        // 创建控制器
        UIViewController *vc = [cl new];
        // 设置背景颜色
        vc.view.backgroundColor = UIColor.whiteColor;
        // 设置图片
        vc.tabBarItem.image = [UIImage imageNamed:picArr[i]];
        // 设置标题
        vc.tabBarItem.title = titleArr[i];
        // 设置选中图片
        vc.tabBarItem.selectedImage = [UIImage imageNamed:picArr[i]];
        // 设置选中颜色
        [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blueColor]} forState:UIControlStateSelected];
        // 添加到动态数组中
        [array addObject:vc];
    }
    
    // 添加控制器
    tb.viewControllers = array;
    
    // 创建侧滑菜单控制器
    MenuViewController *mvc = [MenuViewController new];
    
    // 创建侧滑菜单, 不能放在 viewDidLoad 中
    MMDrawerController *dc = [[MMDrawerController alloc]initWithCenterViewController:tb leftDrawerViewController:mvc];
    
    // 将根控制器设置为侧滑控制器
    [UIApplication sharedApplication].keyWindow.rootViewController = dc;
    // 设置可见宽度
    dc.maximumLeftDrawerWidth = SCREEN_WIDTH * 0.8;
    // 设置打开侧滑菜单手势
    dc.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
    // 设置关闭侧滑菜单手势
    dc.closeDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
}


@end
